package example.cloudsitefeign.controller;

import example.cloudsitefeign.client.SiteManagementClient;
import example.cloudsitefeign.dto.CommonResultDTO;
import example.cloudsitefeign.dto.SiteInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feign/site")
public class SiteFeignController {

    private final SiteManagementClient siteManagementClient;

    // 使用构造器注入
    @Autowired
    public SiteFeignController(SiteManagementClient siteManagementClient) {
        this.siteManagementClient = siteManagementClient;
    }

    @GetMapping("/info/{id}")
    public CommonResultDTO<SiteInfoDTO> getSiteInfo(@PathVariable("id") Long id) {
        // 通过Feign客户端调用远程服务
        return siteManagementClient.getSiteInfoById(id);
    }

    // 您可以根据 SiteManagementClient 中的其他方法，在这里添加更多测试端点
    // 例如，如果 SiteManagementClient 中有 getAllSites() 方法:
    // @GetMapping("/all")
    // public String getAllSitesViaFeign() {
    //     return siteManagementClient.getAllSites();
    // }
}
